<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>

    function deepClone(obj) {
        var result;
        //当输入数据为简单数据类型时直接复制
        if (obj && typeof obj !== 'object') {
            result = obj;
        }
        //当输入数据为对象或数组时
        else if (obj && typeof obj === 'object') {
            //检测输入数据是数组还是对象
            result = Array.isArray(obj) ? [] : {};
            for (let key in obj) {
                if (obj.hasOwnProperty(key)) {
                    if (obj[key] && typeof obj[key] === 'object') {
                        //若当前元素类型为对象时，递归调用
                        result[key] = deepClone(obj[key]);
                    }
                    //若当前元素类型为基本数据类型
                    else {
                        result[key] = obj[key];
                    }
                }

            }
        }
        return result;

    }

    let obj1 = {
        'name': '小小小胖',
        'data': [1, [2, 3], [4, 5]],
    };
    //let obj2 = JSON.parse(JSON.stringify(obj1));//简单深拷贝
    let obj2 = deepClone(obj1)
    obj2.name = "我爱小小小胖";
    obj2.data[1] = ["二", "三"];
    console.log('obj1', obj1)
    console.log('obj2', obj2)

</script>
</body>
</html>